package com.example.wxg.stream.custom.source;

import org.apache.flink.streaming.api.functions.source.ParallelSourceFunction;

/**
 * @author void
 * @date 2021/11/12 12:49
 * @desc 支持并行的
 */
public class MyParallelSource implements ParallelSourceFunction<Long> {

    private Long count = 1L;
    private boolean isRunning = true;
    
    @Override
    public void run(SourceContext<Long> sourceContext) throws Exception {
        while (isRunning){
            sourceContext.collect(count);
            count++;
            //每秒产生一条数据
            Thread.sleep(1000L);
        }
    }

    @Override
    public void cancel() {
        isRunning = false;
    }
}
